<?
if (!defined('BASEPATH')) exit('No direct script access allowed');
/**
 * Planet Ilkom-ub
 *
 * Planet Ilkom-ub
 *
 * @package		Model Posting
 * @author		Ibnoe Daqiqil Id
 * @copyright	Copyright (c) 2008, www.ibnoe.web.id.
 * @link		http://www.ibnoe.web.id
 * @since		Version 1.0
 * @datetime    18-3-2008 12:33
 */
class mdl_site extends Model {

	var $site_id;
	var $name;
	var $site_url;
	var $feed_url;
	var $last_update;
	var $update_interval;

	var $page_num;
	var $limit;
	var $numpages;
	var $paginate;

	function mdl_site() {
		parent::Model();
		$this->limit = 20;
		$this->paginate = TRUE;
	}
	
	function get() {

		$this->_prep_query();
		$query = $this->db->get("site");
		$this->numpages = ceil($query->num_rows / $this->limit);

		if ($this->paginate == TRUE) {
			$offset = ($this->page_num * $this->limit) - $this->limit;
			$this->db->limit($this->limit, $offset);
		}

		$this->_prep_query();
		$query = $this->db->get("site");

		if ($this->site_id) 
		{

			if ($query->row()) {

				return ($query->row());
			}

			else {

				return (FALSE);

			}

		}

		else {

			if ($query->result()) {

				return ($query->result());

			}

			else {

				return (FALSE);

			}

		}

	}

	function save() {

		$dbArray = array(
		"name"	=>	$this->title,
		"site_url"	=>	$this->site_url,
		"feed_url"	=>	$this->feed_url,
		"last_update"	=>	$this->last_update,
		"update_interval"	=>	$this->update_interval);

		if ($this->site_id) {
			$this->db->where("site_id", $this->site_id);
			$this->db->update("site", $dbArray);
		}
		else {
			$this->db->insert("site", $dbArray);
		}

	}

	function delete() {

		$this->db->where("blogroll_id", $this->blogroll_id);
		$this->db->delete("site");

	}

	function _prep_query() {
		if ($this->site_id) {
			$this->db->where("site", $this->site_id);
		}

		$this->db->orderby("name");

	}

}

?>